package org.apache.struts.ehr.medical_records.action;

import java.util.Map;

import org.apache.struts.ehr.medical_records.model.ChangeConsultant;
import org.apache.struts.ehr.medical_records.model.HL7Message;
import org.apache.struts.ehr.medical_records.model.ReplyMessage;

import ca.uhn.hl7v2.model.v251.message.ACK;
import ca.uhn.hl7v2.model.v251.message.ADR_A19;
import ca.uhn.hl7v2.model.v251.message.ADT_A61;
import ca.uhn.hl7v2.model.v251.segment.PID;
import ca.uhn.hl7v2.model.v251.segment.PV1;

import com.earogya.communicate.Communicator;
import com.earogya.logic.medical_records.CreateADTA08;
import com.earogya.logic.medical_records.CreateADTA61;
import com.earogya.logic.medical_records.ParseReply;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ChangeConsultantAction extends ActionSupport{

	private ChangeConsultant changeConsultant;
	private ReplyMessage replyMessage;
	
	public ReplyMessage getReplyMessage() {
		return replyMessage;
	}

	public ChangeConsultant getChangeConsultant() {
		return changeConsultant;
	}

	public void setChangeConsultant(ChangeConsultant changeConsultant) {
		this.changeConsultant = changeConsultant;
	}

	public String execute()throws Exception{
		Map<String, Object> session=ActionContext.getContext().getSession();
		replyMessage=new ReplyMessage();
		replyMessage.setMessage("empty");
		CreateADTA61 createMessage=new CreateADTA61(changeConsultant);
		String msg=createMessage.createMessage("CSTH");
		if(!msg.equals(null)){
			Communicator c=new Communicator();
			String reply=c.sendMessage(msg);
			if(!reply.equals("No Reply")){
				ParseReply parse=new ParseReply();
				replyMessage=(ReplyMessage)parse.parseMessage(reply);
			}
		}
		return SUCCESS;
	}
	
	public void validate(){
		if(changeConsultant.getNew_consultant_id().length()==0){
			addFieldError("transferToAnotherWard.patientId", "This field is required");
		}
	}
}
